// Copyright (c) 2022, hzmes and contributors
// For license information, please see license.txt
/* eslint-disable */

frappe.query_reports["SRM AlterMold Rep"] = {
	"filters": [
		{
			"fieldname": "next_status",
			"fieldtype": "Select",
			"label": "协同审批",
			"options": ['', '待提交','硬件主管','部门经理','中心副总','产品线','采购经理','待完成','已取消','已废止'],
			"default": '',
			"width": 0
		},
		{
			"fieldname": "creation_from",
			"fieldtype": "Date",
			"label": "制单日期从",
			"default": frappe.datetime.add_days(frappe.datetime.get_today(), -100),
			"width": 0
		},
		{
			"fieldname": "creation_to",
			"fieldtype": "Date",
			"label": "制单日期到",
			"default": frappe.datetime.add_days(frappe.datetime.get_today(), 1),
			"width": 0
		},
	],

	onload: function(report) {
		report.page.add_inner_button(__("新增改模申请"), function() {
			
			frappe.new_doc("SRM AlterMold");
		}).addClass('btn-primary')
	},

	"formatter": function(value, row, column, data, default_formatter) {
		
		value = default_formatter(value, row, column, data);
		let format_fields = ["workflow_state"];
		if (format_fields && data && data["workflow_state"]) {
			
			var color_field = data["workflow_state"];
			let color = undefined;	
			if (color_field == '完成') {
				color = 'green';
			}
			if (color_field == '废止') {
				color = 'red';
			}
			if (color_field == '保存') {
				color = 'blue';
			}
			if (color_field == '提交') {
				color = 'orange';
			}
			if (color){
				value =`<div style='margin:0px;padding-left:5px;color:${color}!important;'>${value}</div>`            
			}
		}

		return value;
	},

	get_datatable_options(options) {
        return Object.assign(options, {
            checkboxColumn: true,
			events: {
				onCheckRow: function(data) {
					console.log(onCheckRow)
				},

				onSwitchColumn: function(data) {
					console.log('SwitchColumn')
				},
			}
        });
    },
};
